package com.dongzili.demo.customer.pgsql.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dongzili.demo.common.config.mybatisplus.MybatisPlusUtil;
import com.dongzili.demo.common.vo.ApiResponse;
import com.dongzili.demo.customer.pgsql.model.RelationPG;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/pgsql")
public class PgsqlTestController {

    @GetMapping("/search")
    public ApiResponse<?> search(@RequestParam("keyword") String keyword, @RequestParam(value = "current", defaultValue = "1") Integer current, @RequestParam(value = "size", defaultValue = "10") Integer size) {

        LambdaQueryWrapper<RelationPG> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(RelationPG::getResName, keyword);
        queryWrapper.orderByDesc(RelationPG::getId);
        Page<RelationPG> page = MybatisPlusUtil.getMapper(RelationPG.class).selectPage(new Page<>(current, size),queryWrapper);
        return ApiResponse.success(page);
    }
}
